{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# lab stl output\n",
    "\n",
    "in addition to transforming a fullcontrol ***design*** into a 'plot' ***result*** or a 'gcode' ***result***, it can also be transformed into a '3d_model' ***result*** - that is a 3D model (e.g. stl file) of the simulated as-printed geometry based on `Point` and `ExtrusionGeometry` objects in the ***design*** \n",
    "\n",
    "this notebook briefly demonstrates how the 3D model can be generated"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### FullControl lab import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import fullcontrol as fc\n",
    "import lab.fullcontrol as fclab"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### create a ***design***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "EW, EH = 0.8, 0.3 # extrusion width and height\n",
    "radius, layers = 10, 5\n",
    "design_name = 'test_design'\n",
    "steps = fc.helixZ(fc.Point(x=0, y=0, z=EH), radius, radius, 0, layers, EH, layers*32)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### transform the design to a 'plot' ***result*** to preview it"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fc.transform(steps, 'plot', fc.PlotControls(style='tube', zoom=0.7,\n",
    "             initialization_data={'extrusion_width': EW, 'extrusion_height': EH}))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### ModelControls adjust how a ***design*** is transformed into a '3d_model' ***result***\n",
    "\n",
    "***designs*** are transformed into a 'plot' according to some default settings which can be overwritten with a `PlotControls` object with the following attributes (all demonstrated in this notebook):\n",
    "\n",
    "- `stl_filename` - string for filename (do not include '.stl')\n",
    "- `include_date` - options: True/False (include dates/time-stamp in the stl filename)\n",
    "- `tube_shape` - options: 'rectangle' / 'diamond' / 'hexagon' / 'octagon'  - adjusts cross sectional shape of extrudates in the stl file\n",
    "    - note this is a slightly different format than that used when generating 3D plots using `tube-sides` in a `PlotControls` object\n",
    "- `tube_type` - options: 'flow'/'cylinders' - adjust how the plot transitions from line to line\n",
    "    - see the `PlotControls` tutorial for more info about this parameter\n",
    "- `stl_type` - options: 'ascii'/'binary' - stl file format\n",
    "- `stls_combined` - options: True/False - state whether ***designs*** containing multiple bodies are saved with all bodies in a single stl file - multiple bodies occur if the ***design*** includes non-extruding-travel moves between extruded regions\n",
    "- `initialization_data` - define initial width/height of 3D lines with dictionary: {'extrusion_width': value, 'extrusion_height': value} - these values are used until they are changed by an `ExtrusionGeometry` object in the ***design***"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fclab.transform(steps, '3d_model', fclab.ModelControls(\n",
    "    stl_filename=design_name, \n",
    "    include_date=False, \n",
    "    tube_shape='rectangle',\n",
    "    tube_type= 'flow', \n",
    "    stl_type = 'ascii', \n",
    "    stls_combined = True, \n",
    "    initialization_data={'extrusion_width': EW, 'extrusion_height': EH}))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### colab\n",
    "\n",
    "if using google colab, the stl file can be downloaded from the file browser on the left-hand side or with:\n",
    "\n",
    "```\n",
    "from google.colab import files\n",
    "files.download(f'{design_name}.stl')\n",
    "```\n",
    "(assuming `include_date` is False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fc",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
